# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: David Verelst <david dot verelst at gmail com>
# Contributor: richli

pkgname=python-shapely
pkgver=1.8.5.post1
pkgrel=2
pkgdesc="Manipulation and analysis of geometric objects in the Cartesian plane"
arch=(loong64 x86_64)
url="https://pypi.python.org/pypi/Shapely"
license=(BSD)
depends=(geos python)
optdepends=('python-numpy: for shapely.vectorized submodule')
makedepends=(python-setuptools python-packaging python-numpy cython)
checkdepends=(python-pytest)
source=("https://pypi.io/packages/source/S/Shapely/Shapely-${pkgver}.tar.gz")
sha512sums=('ce629e15a229b3a892442ca419ce9616d5a132c2af4f33450df0c932344ae255b19251c7f722a7465c6e16eab137b01f9ffbecd40d6a22a487d41b9d6db8d417')

prepare() {
  cd Shapely-$pkgver
  rm -r _vendor
  sed -i 's/from _vendor.packaging./from packaging./' setup.py
}

build() {
  cd Shapely-$pkgver
  python setup.py build
}

check() {
  # TODO: make the hack less dirty...

  cd Shapely-$pkgver
  mv shapely shapely.bak
  local python_version=$(python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
  PYTHONPATH="${PWD}"/build/lib.linux-$CARCH-cpython-${python_version/./} pytest -vv --color=yes
  mv shapely.bak shapely
}

package() {
  cd Shapely-$pkgver
  python setup.py install --root="$pkgdir" --optimize=1
  install -Dm644 LICENSE.txt -t "$pkgdir"/usr/share/licenses/$pkgname/
}
